﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="cn_order_info" Codebehind="order_info.aspx.cs" %>


<%@ Register Src="~/cn/UserControl/header.ascx" TagName="header" TagPrefix="uc1" %>
<%@ Register Src="~/cn/UserControl/footer.ascx" TagName="footer" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>填写购物信息，<%=(new Gift.WebApp.BasicSet()).TitleBind() %></title>
    <meta name="Keywords" content="<%=(new Gift.WebApp.BasicSet()).KeywordBind() %>" />
    <meta name="Description" content="<%=(new Gift.WebApp.BasicSet()).DescriptionBind() %>" />
    <link type="text/css" rel="stylesheet" href="/script/css/index.css" />
    <link type="text/css" rel="stylesheet" href="/script/css/member.css" />
    <link type="text/css" rel="stylesheet" href="/script/css/ie.css" />


    <script type="text/javascript" src="/script/js/jquery-1.6.2.min.js"></script>

    <script type="text/javascript">
        function send_request(url, poststr) {
            http_request = false;
            if (window.XMLHttpRequest) {
                http_request = new XMLHttpRequest();
                if (http_request.overrideMimeType) {
                    http_request.overrideMimeType('text/xml');
                }
            } else if (window.ActiveXObject) {
                try {
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) { }
                }
            }
            if (!http_request) return false;
            http_request.onreadystatechange = processRequest;
            http_request.open("POST", url, true);
            http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            http_request.send(poststr);
        }
        function processRequest() {
            if (http_request.readyState == 4) {
                if (http_request.status == 200) {
                    if (http_request.responseText != "")
                        $("#sDeliveryWay").html(http_request.responseText);

                } else { }
            }
        }
        function isDisplayUserAddress(region) {
            var item = $("input[name='userAddress']:checked").val();
            if (item != "0") {
                $("#addUserAddress").hide();
                poststr = "region=" + escape(region);
                send_request('orderInfoHandler.ashx', poststr)
            }
            else {
                $("#addUserAddress").show();
                if ($("#selectProvinces option:selected").val() != "0") {
                    poststr = "region=" + escape($("#selectProvinces option:selected").text());
                    send_request('orderInfoHandler.ashx', poststr)
                }
            }
        }
        function changeDeliveryWay(freight) {
            if ($("#hdFromFreight").val() == "false") {
                $("#sSumFreight").html(changePrice2money("" + parseFloat(freight).toFixed(2) + ""));
                $("#sSumTotal").html("您共需要为订单支付：" + changePrice2money("" + (parseFloat($("#hdGoodsSum").val()) + parseFloat(freight)) + ""));
            } else if ($("#hdFromFreight").val() == "true") {
                $("#sSumFreight").html(changePrice2money("" + parseFloat(0).toFixed(2) + ""));
                $("#sSumTotal").html("您共需要为订单支付：" + changePrice2money("" + (parseFloat($("#hdGoodsSum").val()) + parseFloat(0)) + ""));
            }
        }
        function changePrice2money(s) {
            if (/[^0-9\.]/.test(s)) return "invalid value";
            s = s.replace(/^(\d*)$/, "$1.");
            s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
            s = s.replace(".", ",");
            var re = /(\d)(\d{3},)/;
            while (re.test(s))
                s = s.replace(re, "$1,$2");
            s = s.replace(/,(\d\d)$/, ".$1");
            return "¥" + s.replace(/^\./, "0.")
        }
        $(function () {
            $("#selectProvinces").change(function () {
                $.ajax({
                    type: "POST",
                    url: "region.ashx",
                    data: "pid=" + $("#selectProvinces").val(),
                    success: function (msg) {
                        $("#spanCity").html(msg);
                        $("#spProvinces").html("*");
                    }
                });
                if ($("#selectProvinces option:selected").val() != "0")
                    $.ajax({
                        type: "POST",
                        url: "orderInfoHandler.ashx",
                        data: "region=" + $("#selectProvinces option:selected").text(),
                        success: function (msg) {
                            $("#sDeliveryWay").html(msg);
                        }
                    });
                return false;
            });
            $("#txtConsignee").blur(function () {
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#txtConsignee").val() == "")
                        $("#spConsignee").html("<img src=\"/script/images/wrong.gif\" />请输入收货人姓名！");
                    else $("#spConsignee").html("<img src=\"/script/images/right.gif\"/>");
                }
                return false;
            });
            $("#selectProvinces").blur(function () {
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#selectProvinces").val() == "0")
                        $("#spProvinces").html("<img src=\"/script/images/wrong.gif\" />请选择省份/直辖市！");
                    else $("#spProvinces").html("<img src=\"/script/images/right.gif\"/>");
                }
                return false;
            });
            $("#txtAddress").blur(function () {
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#txtAddress").val() == "")
                        $("#spAddress").html("<img src=\"/script/images/wrong.gif\" />请输入详细地址！");
                    else $("#spAddress").html("<img src=\"/script/images/right.gif\"/>");
                }
                return false;
            });
            $("#txtZipcode").blur(function () {
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#txtZipcode").val() == "")
                        $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />请输入邮政编码！");
                    else {
                        if ($("#txtZipcode").val().match(/^[0-9]{6}$/) == null)
                            $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />邮政编码格式不符！");
                        else $("#spZipcode").html("<img src=\"/script/images/right.gif\"/>");
                    }
                }
                return false;
            });
            $("#txtTelephone").blur(function () {
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#txtTelephone").val() != "") {
                        if ($("#txtTelephone").val().match(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/) == null)
                            $("#spTelephone").html("<img src=\"/script/images/wrong.gif\" />电话号码格式不符！如：0754-88888888");
                        else $("#spTelephone").html("<img src=\"/script/images/right.gif\"/>");
                    } else $("#spTelephone").html("");
                }
                return false;
            });
            $("#txtMobile").blur(function () {
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#txtMobile").val() != "") {
                        if (/^13\d{9}$/g.test($("#txtMobile").val()) || (/^15[0-35-9]\d{8}$/g.test($("#txtMobile").val())) || (/^18[05-9]\d{8}$/g.test($("#txtMobile").val())))
                            $("#spMobile").html("<img src=\"/script/images/right.gif\"/>");
                        else
                            $("#spMobile").html("<img src=\"/script/images/wrong.gif\" />手机号码格式不符！");
                    } else $("#spMobile").html("");
                }
                return false;
            });
            $("#btnOrderSubmit").click(function () {
                if ($("input[name='userAddress']:checked").val() == null) {
                    $("input[name='userAddress']")[0].focus();
                    art.dialog.tips("请选择填写收货地址！", 1.5);
                    return false;
                }
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#txtConsignee").val() == "") {
                        $("#txtConsignee").select();
                        $("#spConsignee").html("<img src=\"/script/images/wrong.gif\" />请输入收货人姓名！");
                        return false;
                    } else $("#spConsignee").html("<img src=\"/script/images/right.gif\"/>");
                    if ($("#selectProvinces").val() == "0") {
                        $("#selectProvinces").focus();
                        $("#spProvinces").html("<img src=\"/script/images/wrong.gif\" />请选择省份/直辖市！");
                        return false;
                    } else $("#spProvinces").html("<img src=\"/script/images/right.gif\"/>");
                    if ($("#selectCity") != null) {
                        if ($("#selectCity").val() == "0") {
                            $("#selectCity").focus();
                            $("#spProvinces").html("<img src=\"/script/images/wrong.gif\" />请选择市(县/区)！");
                            return false;
                        } else $("#spProvinces").html("<img src=\"/script/images/right.gif\"/>");
                    }
                    if ($("#txtAddress").val() == "") {
                        $("#txtAddress").select();
                        $("#spAddress").html("<img src=\"/script/images/wrong.gif\" />请输入详细地址！");
                        return false;
                    } else $("#spAddress").html("<img src=\"/script/images/right.gif\"/>");
                    if ($("#txtZipcode").val() == "") {
                        $("#txtZipcode").select();
                        $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />请输入邮政编码！");
                        return false;
                    } else {
                        if ($("#txtZipcode").val().match(/^[0-9]{6}$/) == null) {
                            $("#txtZipcode").select();
                            $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />邮政编码格式不符！");
                            return false;
                        } else $("#spZipcode").html("<img src=\"/script/images/right.gif\"/>");
                    }
                    if ($("#txtTelephone").val() == "" && $("#txtMobile").val() == "") {
                        $("#txtTelephone").select();
                        $("#spTelephone").html("");
                        $("#spMobile").html("<img src=\"/script/images/wrong.gif\" />联系电话和手机号码至少填写一项！");
                        return false;
                    }
                    else $("#spMobile").html("");
                    if ($("#txtTelephone").val() != "") {
                        if ($("#txtTelephone").val().match(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/) == null) {
                            $("#txtTelephone").select();
                            $("#spTelephone").html("<img src=\"/script/images/wrong.gif\" />电话号码格式不符！如：0754-88888888");
                            return false;
                        } else $("#spTelephone").html("<img src=\"/script/images/right.gif\"/>");
                    } else $("#spTelephone").html("");
                    if ($("#txtMobile").val() != "") {
                        if (/^13\d{9}$/g.test($("#txtMobile").val()) || (/^15[0-35-9]\d{8}$/g.test($("#txtMobile").val())) || (/^18[05-9]\d{8}$/g.test($("#txtMobile").val()))) {
                            $("#spMobile").html("<img src=\"/script/images/right.gif\"/>");
                        } else {
                            $("#txtMobile").select();
                            $("#spMobile").html("<img src=\"/script/images/wrong.gif\" />手机号码格式不符！");
                            return false;
                        }
                    } else $("#spMobile").html("");
                }
                if ($("input[name='deliveryWay']:checked").val() == null) {
                    $("input[name='deliveryWay']")[0].focus();
                    art.dialog.tips("请选择配送方式！", 1.5);
                    return false;
                }
                if ($("input[name='pay_bank']:checked").val() == null) {
                    $("input[name='pay_bank']")[0].focus();
                    art.dialog.tips("请选择支付方式！", 1.5);
                    return false;
                }
                if ($("#txtaPostscript").val().length > 200) {
                    $("#txtaPostscript").select();
                    $("#spPostscript").html("<img src=\"/script/images/wrong.gif\" />附言不能超过200个字符！");
                    return false;
                }
                else $("#spPostscript").html("<img src=\"/script/images/right.gif\"/>");
                var da = "";
                if ($("input[name='userAddress']:checked").val() == "0") {
                    if ($("#selectCity option:selected").text() != "")
                        da = "&userAddress=0&consignee=" + escape($("#txtConsignee").val()) + "&provinces=" + escape($("#selectProvinces option:selected").text()) + "&city=" + escape($("#selectCity option:selected").text()) + "&address=" + escape($("#txtAddress").val()) + "&zipCode=" + $("#txtZipcode").val() + "&telephone=" + $("#txtTelephone").val() + "&mobile=" + $("#txtMobile").val() + "&isSave=" + $("input[name='isSave']:checked").val();
                    else
                        da = "&userAddress=0&consignee=" + escape($("#txtConsignee").val()) + "&provinces=" + escape($("#selectProvinces option:selected").text()) + "&city=&address=" + escape($("#txtAddress").val()) + "&zipCode=" + $("#txtZipcode").val() + "&telephone=" + $("#txtTelephone").val() + "&mobile=" + $("#txtMobile").val() + "&isSave=" + $("input[name='isSave']:checked").val();
                }
                else {
                    da = "&userAddress=" + $("input[name='userAddress']:checked").val();
                }
                art.dialog.tips("订单提交中，请耐心等候！", 30);
                $.ajax({
                    type: "POST",
                    url: "orderInfoHandler.ashx",
                    data: "deliveryWay=" + $("input[name='deliveryWay']:checked").val() + "&pay_bank=" + $("input[name='pay_bank']:checked").val() + da + "&postscript=" + escape($("#txtaPostscript").val()) + "&goodsSum=" + $("#hdGoodsSum").val(),
                    success: function (msg) {
                        if (msg == "1") {
                            art.dialog.tips("卡券余额与所兑换商品价格不符，请重新设置商品数量或者重新选择商品！", 10);
                        }
                        else if (msg == "1") {
                            art.dialog.tips("订单提交不成功！", 10);
                        }
                        else if (msg != "0") {
                            window.location = "order_result.html?orderNo=" + msg + "&pay_bank=" + escape($("input[name='pay_bank']:checked").val());
                        }
                    }
                });
                return false;
            });
        });
    </script>

</head>
<body>
    <uc1:header ID="Header1" runat="server" />
    <div class="container">
        <form id="orderForm" action="" method="post">
            <div class="rightcontent shop_cart">
                <h5 class="second">
                    <span>1.我的购物车</span><span><strong>2.填写购物信息</strong></span><span>3.成功下订</span></h5>
                <div class="contain">
                    <h6>
                        收货地址:</h6>
                    <%Response.Write(UserAddressBind()); %>
                    <span>
                        <input type="radio" name="userAddress" value="0" onclick="isDisplayUserAddress('0');" />
                        填写收货地址</span>
                    <div class="content" id="addUserAddress" style="display: none;">
                        <p>
                            <label for="txtConsignee">
                                收货人姓名：</label><input id="txtConsignee" type="text" maxlength="20" /><span id="spConsignee">*</span></p>
                        <%Response.Write(ProvincesBind()); %>
                        <p>
                            <label for="txtAddress">
                                详细地址：</label><input id="txtAddress" maxlength="200" type="text" /><span id="spAddress">*</span></p>
                        <p>
                            <label for="[data]">
                                邮政编码：</label><input id="txtZipcode" maxlength="20" type="text" /><span id="spZipcode">*</span></p>
                        <p>
                            <label for="[data]">
                                联系电话：</label><input id="txtTelephone" maxlength="50" type="text" /><span id="spTelephone"></span></p>
                        <p>
                            <label for="[data]">
                                手机号码：</label><input id="txtMobile" maxlength="50" type="text" /><span id="spMobile">*
                                    联系电话和手机号码至少填写一项</span></p>
                        <p class="radio_input" >
                            <label for="[data]">
                                是否保存：</label>
                             <input id="rdSave1" type="radio" name="isSave" value="1" checked="checked" />是
                            <input id="rdSave0" type="radio" name="isSave" value="0" />否</p>
                    </div>
                    <span id="sDeliveryWay">
                        <%Response.Write(DeliveryWayBind()); %>
                    </span>
                    <h6>
                        支付方式：</h6>
                    <table class="firsttable">
                        <%Response.Write(PaymentBind()); %>
                       
                    </table>
                    <% Response.Write(PostscriptBind()); %>
                </div>
                <div class="contain">
                    <p class="textright">
                        <a href="/cn/shopping_cart.html">回到购物车，修改产品 >></a></p>
                    <p>
                        产品清单：</p>
                    <table>
                        <tr>
                            <th>
                                商品货号</th>
                            <th>
                                商品图片</th>
                            <th>
                                商品名称</th>
                            <th>
                                销售价格</th>
                            <th>
                                数量</th>
                            <th>
                                小计</th>
                        </tr>
                        <%Response.Write(ShoppingCartBind()); %>
                    </table>
                    <%Response.Write(ShoppingCartTotalBind()); %>
                    <p class="textright">
                        请核对以上信息，确认无误后点击“提交订单”<br />
                        <input id="btnOrderSubmit" type="submit" class="saile_submit" value="提交订单" /></p>
                </div>
            </div>
        </form>
        <!--end rightcontent-->
        <span class="clear"></span>
    </div>
    <uc2:footer ID="Footer1" runat="server" />
</body>
</html>
